package ${basePackageName}.ctrl;

import ${basePackageName}.service.${vName?cap_first}Service2;
import org.slf4j.LoggerFactory;
import ch.qos.logback.classic.Logger;
import com.alibaba.fastjson.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.xisoft.core.common.strhelp.StringHelp;
import com.xisoft.core.data.enums.DataErrorMessage;

/**
 * 
 * @author      作者：${author}
 * @create      创建时间：${createAt}
 * @update      修改时间：${createAt}
 */

@RestController
@RequestMapping("/${vName?lower_case}")
public class ${vName?cap_first}Ctrl {

    private static Logger Log = (Logger) LoggerFactory.getLogger(${vName?cap_first}Ctrl.class);

    @Autowired
    private ${vName?cap_first}Service service;

    @ResponseBody
    @RequestMapping(value = "/Save", method = RequestMethod.POST)
    public String Save(@RequestBody String jsonStr) throws Exception {
        Log.info("调用${vName?cap_first}Ctrl的Save方法：" + jsonStr);

        if (StringHelp.IsNullOrEmpty(jsonStr)) {
            throw new Exception(DataErrorMessage.PARAM_IS_NULL_OR_EMPTY.getDesc());
        }
        JSONObject jsonObject = new JSONObject();
        try {
            jsonObject = service.businessBillSave(JSONObject.parseObject(jsonStr));
        } catch (Exception e) {
            Log.info("调用${vName?cap_first}Ctrl的Save方法：" + e.toString());
            throw new Exception(e.getMessage());
        }
        return jsonObject.toJSONString();
    }

    @ResponseBody
    @RequestMapping(value = "/Delete", method = RequestMethod.POST)
    public String Delete(@RequestBody String jsonStr) throws Exception {
        Log.info("调用${vName?cap_first}Ctrl的Delete方法：" + jsonStr);

        if (StringHelp.IsNullOrEmpty(jsonStr)) {
            throw new Exception(DataErrorMessage.PARAM_IS_NULL_OR_EMPTY.getDesc());
        }
        JSONObject jsonObject = new JSONObject();
        try {
            jsonObject = service.businessBillDelete(JSONObject.parseObject(jsonStr));
        } catch (Exception e) {
            Log.info("调用${vName?cap_first}Ctrl的Delete方法：" + e.toString());
            throw new Exception(e.getMessage());
        }
        return jsonObject.toJSONString();
    }

    @ResponseBody
    @RequestMapping(value = "/Update", method = RequestMethod.POST)
    public String Update(@RequestBody String jsonStr) throws Exception {
        Log.info("调用${vName?cap_first}Ctrl的Update方法：" + jsonStr);

        if (StringHelp.IsNullOrEmpty(jsonStr)) {
            throw new Exception(DataErrorMessage.PARAM_IS_NULL_OR_EMPTY.getDesc());
        }
        JSONObject jsonObject = new JSONObject();
        try {
            jsonObject = service.businessBillUpdate(JSONObject.parseObject(jsonStr));
        } catch (Exception e) {
            Log.info("调用${vName?cap_first}Ctrl的Update方法：" + e.toString());
            throw new Exception(e.getMessage());
        }
        return jsonObject.toJSONString();
    }

    @ResponseBody
    @RequestMapping(value = "/Query", method = RequestMethod.POST)
    public String Query(@RequestBody String jsonStr) throws Exception {
        Log.info("调用${vName?cap_first}Ctrl的Query方法：" + jsonStr);

        if (StringHelp.IsNullOrEmpty(jsonStr)) {
            throw new Exception(DataErrorMessage.PARAM_IS_NULL_OR_EMPTY.getDesc());
        }
        JSONObject jsonObject = new JSONObject();
        try {
            jsonObject = service.businessBillQuery(JSONObject.parseObject(jsonStr));
        } catch (Exception e) {
            Log.info("调用${vName?cap_first}Ctrl的Query方法：" + e.toString());
            throw new Exception(e.getMessage());
        }
        return jsonObject.toJSONString();
    }

    @ResponseBody
    @RequestMapping(value = "/QueryConfig", method = RequestMethod.POST)
    public String QueryConfig(@RequestBody String jsonStr) throws Exception {
        Log.info("调用${vName?cap_first}Ctrl的Query方法：" + jsonStr);
        if (StringHelp.IsNullOrEmpty(jsonStr)) {
            throw new Exception(DataErrorMessage.PARAM_IS_NULL_OR_EMPTY.getDesc());
        }
        JSONObject jsonObject = new JSONObject();
        try {
            jsonObject = service.businessBillQueryConfig(JSONObject.parseObject(jsonStr));
        } catch (Exception e) {
            Log.info("调用${vName?cap_first}Ctrl的QueryConfig方法：" + e.toString());
            throw new Exception(e.getMessage());
        }
        return jsonObject.toJSONString();
    }
}
